<?php
defined('BASEPATH') OR exit('No direct script access allowed');



/**
 * form_validation 表单验证基本配置
 *
 * @author 	Jason
 * @version	1.0.0
 * @date	2017年4月26日 下午3:38:07
 * 
 * @version	1.1.0
 * @date	2017年4月28日 下午7:05:02
 * 
 * @see     创建类库 - 初始化类时传入参数
 * @link    https://codeigniter.org.cn/user_guide/general/creating_libraries.html#id6
 * 
 * @see     表单验证类 - 将一系列验证规则保存到一个配置文件
 * @link    https://codeigniter.org.cn/user_guide/libraries/form_validation.html#saving-groups
 * 
 * @see     表单验证类 - 设置错误信息
 * @link    https://codeigniter.org.cn/user_guide/libraries/form_validation.html#setting-error-messages
 */
/*
 |--------------------------------------------------------------------------
 | Form_validation Rule Errors
 |--------------------------------------------------------------------------
 |
 | 默认的表单验证错误
 | 
 | 定义 common 子数组用于手工调用 ( NOT for any action! )，调用方式如下
 | 
		$this->CI->load->library('form_validation');
		
		$this->CI->config->load('form_validation', !true);
		$errors = $this->CI->config->item('errors', 'common');
		
		OR
		
		$this->CI->config->load('form_validation', !false);
		$errors = $this->CI->config->item('common', 'form_validation')['errors'];
 |
 */
// MARK 基础验证规则
// $config['rules']['errors'] = [
// 		'required' => 'passport_msg_{field}_empty',
// 		'matches' => 'passport_msg_{field}_not_match',
// 		'is_unique' => 'passport_msg_{field}_unavailable',
// 		'valid_email' => 'passport_msg_{field}_invalid',
// ];
$errors = [
// 		# 注意：系统验证函数语言包系统自带
// 		'required' => 'passport_msg_{field}_empty',
// 		'matches' => 'passport_msg_{field}_not_match',
// 		'is_unique' => 'passport_msg_{field}_unavailable',
// 		'valid_email' => 'passport_msg_{field}_invalid',
];
$config['common'] = [
		'errors' => $errors,
];

# var_dump($this); // class CI_Loader#15 (10) { ... }
$this->CI =& get_instance();

// MARK 登录注册验证规则
$config['register'] = [
		[
				'field' => 'name',
				'label' => 'lang: passport_field_name',
				'rules' => 'trim|required|is_unique[member.name]',
				'errors' => $errors,
		],
		[
				'field' => 'password',
				'label' => 'lang: passport_field_password',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'passconf',
				'label' => 'lang: passport_field_passconf',
				'rules' => 'trim|required|matches[password]',
				'errors' => $errors,
		],
		[
				'field' => 'email',
				'label' => 'lang: passport_field_email',
				'rules' => 'trim|required|valid_email|is_unique[member.email]',
				'errors' => $errors,
		],
		[
				'field' => 'agreement',
				'label' => 'lang: passport_field_agreement',
				'rules' => 'required',
				'errors' => $errors,
		],
];

$config['login'] = [
		[
				'field' => 'name',
				'label' => 'lang: passport_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'password',
				'label' => 'lang: passport_field_password',
				'rules' => 'trim|required',
				'errors' => $errors,
		]
];


// MARK 找回密码验证规则
$config['recovery_submit_eamil'] = [
		[
				'field' => 'email',
				'label' => 'lang: passport_field_email',
				// MARK 这里通过修改 CI-Libraries-Form_validation Callable 也可带第二个参数，仅限字符串
				#'rules' => 'trim|required|valid_email|callback_is_not_unique[member.email]',
				'rules' => [
						'trim',
						'required',
						'valid_email',
// 						'callback_is_not_unique[member.email]'
// 						[
// 								'passport_msg_email_not_exist[member.email]',
// 								function ($str, $field){
// 									var_dump($str, $field);
// 									return true;
// 								}
// 						],
						[
								'passport_msg_email_not_exist[member.email]',
								[$this->CI->lib_passport, 'is_not_unique'],
						],
				],
				'errors' => $errors,
		],
];

$config['recovery_reset'] = [
		[
				'field' => 'token',
				'label' => 'lang: passport_field_token',
				'rules' => [
						'trim',
						'required',
						[
								'passport_msg_token_invalid',
								[$this->CI->lib_passport, 'is_token_valid'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'password',
				'label' => 'lang: passport_field_password',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'passconf',
				'label' => 'lang: passport_field_passconf',
				'rules' => 'trim|required|matches[password]',
				'errors' => $errors,
		],
];


// MARK 修改密码验证规则
$config['change_password'] = [
		[
				'field' => 'opassword',
				'label' => 'lang: passport_field_password_origin',
				'rules' => [
						'trim',
						'required',
						[
								'passport_msg_password_invalid',
								[$this->CI->lib_passport, 'is_password_valid'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'password',
				'label' => 'lang: passport_field_password_new',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'passconf',
				'label' => 'lang: passport_field_passconf_new',
				'rules' => 'trim|required|matches[password]',
				'errors' => $errors,
		],
];


// MARK 地区验证规则
$config['area_create'] = [
		[
				'field' => 'name',
				'label' => 'name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'parent_id',
				'label' => 'parent_id',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				// MARK DONE 对于语言标识的提交，如果是必填项，则应该符合取值范围要求，否则就拦截提交，而不是默默地改为默认值！
				// MARK 新控制器中自定义的验证函数也可放到 Library 中，并将错误消息直接交给语言包！
				#'rules' => 'trim|required',
				#'rules' => 'trim|required|callback_token_valid',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
];
$config['area_create_language'] = [
		[
				'field' => 'resource',
				'label' => 'lang: language_field_resource',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'name',
				'label' => 'name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
];


// MARK 语言验证规则
$config['language_create'] = [
		[
				'field' => 'module',
				'label' => 'lang: language_field_module',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'resource',
				'label' => 'lang: language_field_resource',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'field_name',
				'label' => 'lang: language_field_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'field_value',
				'label' => 'lang: language_field_field_value',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
];


// MARK 商户验证规则
$merchant_ml_fields = [
		[
				'field' => 'name',
				'label' => 'lang: merchant_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
// 		[
// 				'field' => 'abstract',
// 				'label' => 'lang: merchant_field_abstract',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
// 		[
// 				'field' => 'summary',
// 				'label' => 'lang: merchant_field_summary',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
		#[
		#		'field' => 'street',
		#		'label' => 'lang: merchant_field_street',
		#		'rules' => 'trim|required',
		#		'errors' => $errors,
		#],
// 		[
// 				'field' => 'address',
// 				'label' => 'lang: merchant_field_address',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
];

$config['merchant_create'] = [
		[
				'field' => 'name',
				'label' => 'lang: merchant_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
];
$config['merchant_create'] = array_merge($config['merchant_create'], $merchant_ml_fields);

$config['merchant_create_language'] = [
		[
				'field' => 'resource',
				'label' => 'lang: language_field_resource',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
];
$config['merchant_create_language'] = array_merge($config['merchant_create_language'], $merchant_ml_fields);


// MARK 路线验证规则
$touroute_ml_fields = [
		[
				'field' => 'name',
				'label' => 'lang: touroute_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		#[
		#		'field' => 'street',
		#		'label' => 'lang: merchant_field_street',
		#		'rules' => 'trim|required',
		#		'errors' => $errors,
		#],
// 		[
// 				'field' => 'address',
// 				'label' => 'lang: merchant_field_address',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
// 		[
// 				'field' => 'product_name',
// 				'label' => 'lang: touroute_field_product_name',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
		[
				'field' => 'summary',
				'label' => 'lang: touroute_field_summary',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'detail',
				'label' => 'lang: touroute_field_detail',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'business_hour',
				'label' => 'lang: touroute_field_business_hour',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'departure_time',
				'label' => 'lang: touroute_field_departure_time',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'departure_point',
				'label' => 'lang: touroute_field_departure_point',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'cost_inclusion',
				'label' => 'lang: touroute_field_cost_inclusion',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'cost_exclusion',
				'label' => 'lang: touroute_field_cost_exclusion',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'cancellation_policy',
				'label' => 'lang: touroute_field_cancellation_policy',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'voucher_information',
				'label' => 'lang: touroute_field_voucher_information',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'participation_notice',
				'label' => 'lang: touroute_field_participation_notice',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
];

$config['touroute_create'] = [
		[
				'field' => 'merchant_id',
				'label' => 'lang: merchant_field_id',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'name',
				'label' => 'lang: touroute_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
];
$config['touroute_create'] = array_merge($config['touroute_create'], $touroute_ml_fields);


$config['touroute_create_language'] = [
		[
				'field' => 'resource',
				'label' => 'lang: language_field_resource',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
];
$config['touroute_create_language'] = array_merge($config['touroute_create_language'], $touroute_ml_fields);


// MARK 广告验证规则
// MARK 开发调试过程中发现一个问题：无论哪个控制器的哪个方法被加载，整个 Form_validation 配置文件都要载入，因此如果验证规则里面某个 Lib 对象还没被加载会报错！- 这个如何破？
// eg: manage/area/ajax_create/?debug=1
// trigger A PHP Error was encountered \
// with Severity: Notice \
// with MEssage: Undefined property: Area::$lib_advertisement \
// in Filename: config/form_validation.php \
// on Line Number: 510
// Solution 1: $this->CI->load->library('lib_advertisement'); // 简单粗暴
// Solution 2: [ & $this->CI->lib_advertisement, 'is_not...'] // 优雅文明
$config['advertisement_create'] = [
		[
				'field' => 'position_id',
				'label' => 'lang: advertisement_field_position_id',
				'rules' => [
						'trim',
						'required',
						[
								'advertisement_msg_advertisement_position_notfound',
								[ & $this->CI->lib_advertisement, 'is_not_unique_fake_to_has_position_exists'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'name',
				'label' => 'lang: advertisement_field_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
];
$config['advertisement_position_create'] = [
		[
				'field' => 'type',
				'label' => 'lang: advertisement_field_position_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_advertisement, 'is_supported_type'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'name',
				'label' => 'lang: advertisement_field_position_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
];


// MARK 角色验证规则：角色 权限 访问控制列表
$config['role_create'] = [
		[
				'field' => 'name',
				'label' => 'lang: role_field_name',
				// TODO Bad work on Update!
				'rules' => 'trim|required', // |is_unique[role.name] - Bad work on Update!
				'errors' => $errors,
		],
];
$config['role_action_create'] = [
		[
				'field' => 'code',
				'label' => 'lang: role_field_action_code',
				// TODO Bad work on Update!
				'rules' => 'trim|required', // |is_unique[role_action.code] - Bad work on Update!
				'errors' => $errors,
		],
		[
				'field' => 'name',
				'label' => 'lang: role_field_action_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
];
$config['role_acl_create'] = [
		[
				'field' => 'role_id',
				'label' => 'lang: role_field_acl_role_id',
				'rules' => [
						'trim',
						'required',
						[
								'role_msg_role_notfound',
								[ & $this->CI->lib_role, 'has_role_exists'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'action_id',
				'label' => 'lang: role_field_acl_action_id',
				'rules' => [
						'trim',
						'required',
						[
								'role_msg_action_notfound',
								[ & $this->CI->lib_role, 'has_action_exists'],
						],
				],
				'errors' => $errors,
		],
];
$config['role_acl_flush'] = [
		[
				'field' => 'role_id',
				'label' => 'lang: role_field_acl_role_id',
				'rules' => [
						'trim',
						'required',
						[
								'role_msg_role_notfound',
								[ & $this->CI->lib_role, 'has_role_exists'],
						],
				],
				'errors' => $errors,
		],
		[
				//'field' => 'action_ids[]',多次，分传
				'field' => 'action_ids',//数组不接
				'label' => 'lang: role_field_acl_action_id',
				'rules' => [
						'trim',
						/*'required',*/
						[
								'role_msg_action_notfound',
								[ & $this->CI->lib_role, 'filter_action_list'],
						],
				],
				'errors' => $errors,
		],
];

// MARK 用户管理验证规则
// $this->CI->load->library('lib_role');
// Solution 2: [ & $this->CI->lib_role, 'has_role_exists'] // 优雅文明
// MARK 虽然在 form_validation 配置文件中使用 [ & Solution 2 ] 避免了错误，
//      但是 MaRK 广告验证规则 那里之所以能顺利运行，是因为调用的是 library 本身，验证发起时对象肯定存在，而这里不同，需要预先 load!
//      不过，可以把有时候必须加载的库函数放到最后 - 延迟加载，详情参见 Lib_member::create_member_with_info() MaRK 验证所需库函数对象 "懒加载" 部分。
// <h4>A PHP Error was encountered</h4>
// <p>Severity: Warning</p>
// <p>Message:  preg_match() expects parameter 2 to be string, array given</p>
// <p>Filename: libraries/Form_validation.php</p>
// <p>Line Number: 716</p>
$config['member_with_info_create'] = [
		[
				'field' => 'role_id',
				'label' => 'lang: passport_field_role_id',
				'rules' => [
						'trim',
						'required',
						[
								'passport_msg_member_role_notfound',
								[ & $this->CI->lib_role, 'has_role_exists'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'name',
				'label' => 'lang: passport_field_name',
				'rules' => 'trim|required|is_unique[member.name]',
				'errors' => $errors,
		],
		[
				'field' => 'email',
				'label' => 'lang: passport_field_email',
				'rules' => 'trim|required|valid_email|is_unique[member.email]',
				'errors' => $errors,
		],
// 		# if (!empty($post['use_default_password']) || empty($post['password'])) { $post['password'] = $default_password; }
// 		[
// 				'field' => 'password',
// 				'label' => 'lang: passport_field_password',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
// 		[
// 				'field' => 'passconf',
// 				'label' => 'lang: passport_field_passconf',
// 				'rules' => 'trim|required|matches[password]',
// 				'errors' => $errors,
// 		],

];

$config['member_with_info_update'] = [
		[
				'field' => 'id',
				'label' => 'lang: passport_field_id',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
];


// 更新用户密码 - 管理员操作，高级权限：不需要原密码验证！
$config['member_password_update'] = [
		[
				'field' => 'id',
				'label' => 'lang: passport_field_id',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
// 		[
// 				'field' => 'opassword',
// 				'label' => 'lang: passport_field_password_origin',
// 				'rules' => [
// 						'trim',
// 						'required',
// 						[
// 								'passport_msg_password_invalid',
// 								[$this->CI->lib_passport, 'is_password_valid'],
// 						],
// 				],
// 				'errors' => $errors,
// 		],
		[
				'field' => 'password',
				'label' => 'lang: passport_field_password_new',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'passconf',
				'label' => 'lang: passport_field_passconf_new',
				'rules' => 'trim|required|matches[password]',
				'errors' => $errors,
		],
];

// MARK 按正向标签切换状态
$config['toggle_status_positive_tag'] = [
		[
				'field' => 'id',
				'label' => 'lang: ID',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
		[
				'field' => 'tag',
				'label' => 'lang: status_positive_tag',
				'rules' => 'trim|required|in_list[unlimited,checked,activated,enabled]',
				'errors' => $errors,
		],
];
$config['toggle_status_positive_tag_for_opinion'] = [
		[
				'field' => 'id',
				'label' => 'lang: ID',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
		[
				'field' => 'tag',
				'label' => 'lang: status_positive_tag',
				'rules' => 'trim|required|in_list[sticky,check_over,checked,enabled]',
				'errors' => $errors,
		],
];
$config['toggle_status_positive_tag_for_message'] = [
		[
				'field' => 'id',
				'label' => 'lang: ID',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
		[
				'field' => 'tag',
				'label' => 'lang: status_positive_tag',
				'rules' => 'trim|required|in_list[read,retained]',
				'errors' => $errors,
		],
];

// MARK 标签验证规则（标签系统，Tag!）
$config['tag_create'] = [
		[
				'field' => 'module',
				'label' => 'lang: tag_field_module',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_tag, 'is_supported_module'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'parent_id',
				'label' => 'lang: tag_field_parent_id',
				'rules' => [
						'trim',
						'required',
						[
								'tag_msg_tag_notfound',
								[ & $this->CI->lib_tag, 'has_tag_exists'],
						],
				],
				'errors' => $errors,
		],
		// TODO name 的去重验证函数
		// TODO 添加和修改同名的分开验证
// 		[
// 				'field' => 'name',
// 				'label' => 'lang: tag_field_name',
// 				'rules' => 'trim|required',
// 				'errors' => $errors,
// 		],
		[
				'field' => 'language',
				'label' => 'lang: language_field_language',
				'rules' => [
						'trim',
						'required',
						[
								'language_msg_language_unsupported',
								[$this->CI->lib_language, 'is_supported_language'],
						],
				],
				'errors' => $errors,
		],
];



// MARK 观点验证规则（观点系统，Opinion!）
$config['opinion_create'] = [
		[
				'field' => 'master_id',
				'label' => 'lang: opinion_field_master_id',
				'rules' => [
						'trim',
// 						'required',
						[
								'tag_msg_tag_notfound',
								[ & $this->CI->lib_opinion, 'has_opinion_exists'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'resource_type',
				'label' => 'lang: opinion_field_resource_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_opinion, 'is_supported_resource_type'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'source_type',
				'label' => 'lang: opinion_field_source_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_opinion, 'is_supported_source_type'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'target_type',
				'label' => 'lang: opinion_field_target_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_opinion, 'is_supported_target_type'],
						],
				],
				'errors' => $errors,
		],
];


// MARK 小动作验证规则（小动作系统，Trick!）
$config['trick_create'] = [
		[
				'field' => 'type',
				'label' => 'lang: trick_field_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_trick, 'is_supported_type'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'source_type',
				'label' => 'lang: trick_field_source_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_trick, 'is_supported_source_type'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'target_type',
				'label' => 'lang: trick_field_target_type',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_trick, 'is_supported_target_type'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'source_id',
				'label' => 'lang: trick_field_source_id',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
		[
				'field' => 'target_id',
				'label' => 'lang: trick_field_target_id',
				'rules' => 'trim|required|is_natural_no_zero',
				'errors' => $errors,
		],
];


// MARK 消息验证规则（消息系统!）
$config['message_template_create'] = [
		[
				'field' => 'name',
				'label' => 'lang: message_field_template_name',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'code',
				'label' => 'lang: message_field_template_code',
				// TODO Bad work on Update!
				// MARK 下面这里 required 规则是必须的，如果没有的话，用户又没提交，后续的都不会执行到了，下同！
				'rules' => 'trim|required|regex_match[/^\\w+$/]', // alpha_numeric // |is_unique[message_template.code] - Bad work on Update!
				'errors' => $errors,
		],
		[
				'field' => 'model',
				'label' => 'lang: message_field_template_model',
				'rules' => 'trim|required',
				'errors' => $errors,
		],
		[
				'field' => 'oper',
				'label' => 'lang: message_field_template_oper',
				// MARK 下面规则里正则表达式中的 + 是 OK 的！如果为空，不会返回匹配失败！注意是不会，是 + ！
				'rules' => 'trim|regex_match[/^\\w+$/]', // alpha_numeric
				'errors' => $errors,
		],
		[
				'field' => 'value',
				'label' => 'lang: message_field_template_value',
				'rules' => 'trim|regex_match[/^\\w+$/]',
				'errors' => $errors,
		],
		[
				'field' => 'delay_duration',
				'label' => 'lang: message_field_template_delay_duration',
				'rules' => 'trim|intval|is_natural', // 自然数，默认为0
				'errors' => $errors,
		],
		[
				'field' => 'other',
				'label' => 'lang: message_field_template_other',
				'rules' => 'trim|regex_match[/^\\w+$/]',
				'errors' => $errors,
		],
		[
				'field' => 'medium',
				'label' => 'lang: message_field_template_medium',
				'rules' => [
						'trim',
						'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_message, 'is_supported_medium'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'channel',
				'label' => 'lang: message_field_template_channel',
				'rules' => [
						'trim',
						'intval',//目前不必须，但要自然数
						'is_natural',
						//'required',
						[
								'common_msg_enum_field_unsupported',
								[ & $this->CI->lib_message, 'is_supported_channel'],
						],
				],
				'errors' => $errors,
		],
		[
				'field' => 'extra',
				'label' => 'lang: message_field_template_extra',
				'rules' => 'trim',
				'errors' => $errors,
		],
];
